/**
 * @file    framework/database.h
 * @brief   Include all components of the database framework
 ****************************************************************************
 * @version 0.6.030 $Id: database.h 1690 2010-01-25 05:19:57Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/*! @namespace wosh::database
 * @brief     Contains classes regarding data persistence. 
 *            Note that XML serialization is required by network overlay.
 *            Database is related to serialization and data persistence (on disk),
 *            actually XML format is widely supported by built-in objects.
 * @deprecated wosh::database will be replaced with wosh::persistence asap.
 * @see       Refer to wosh::DataBase interface and wosh::DataBaseManager core-module.
 * @see       \ref page_framework_database
 *
 ****************************************************************************/
/*! \page page_framework
 * \htmlonly <hr/> \endhtmlonly
 * \section page_framework_database WOSH DataBase Framework [deprecated]
 *
 * [..]
 *
 * @deprecated wosh::database will be replaced with wosh::persistence asap.
 *
 * XML [..]
 * included by default
 *
 * \code

 * \endcode
 *
 *
 * \code
WRESULT BuildingManagerBundle::loadObjects() {
	FilePath xmlFile;
	if ( !xmlFile.set( Properties.getPropertyValue(_BuildingManager_KEY_DB).getData() ) ) {
		SystemError::raise(this, Log, SystemError::CRITICAL, 0, "loadObjects", "FAILED#1 Invalid Archive File [%s]", xmlFile.getPath().c_str() );
		return WRET_ERR_PARAM;
	 }
	if ( !xmlFile.exists() ) {
		SystemError::raise(this, Log, SystemError::CRITICAL, 0, "loadObjects", "FAILED#1 Archive File doesn't exists %s [%s]!", xmlFile.getPath().c_str(), xmlFile.getPathLocal().c_str() );
		return WRET_ERR_PARAM;
	 }
	// may also be a folder of .xml files
	Log.log( Logger::VERBOSE, ":loadObjects() File %s ..", xmlFile.getPathLocal().c_str() );

	std::vector<Serializable*> objects_load;
	WRESULT ret = DataBaseManager::loadObjects( objects_load, "", xmlFile.getPathLocal(), "xml" );

	if ( WFAILED(ret) ) {
		SystemError::raise(this, Log, SystemError::CRITICAL, 0, "loadObjects", "FAILED#%i loading Database %s..", ret, xmlFile.getPathLocal().c_str() );
		return ret;
	 }
	if ( objects_load.size() == 0 ) {
		Log.log( Logger::WARNING, ":loadObjects() : No Items found in database.." );
		return WRET_OK;
	 }

	// register objects
	this->objects.mutex().lockForWrite();
	std::vector<Serializable*>::iterator it_load;
	for ( it_load=objects_load.begin(); it_load!=objects_load.end(); it_load++ ) {
		BuildingObject* currObj = dynamic_cast<BuildingObject*>(*it_load);
		if ( currObj == NULL ) continue;
		addObject_( currObj );
	 }

	// [..]
 }

\endcode
 *
 *
 * SQL [..]
 * SQL is not included by default, you have to define a flag in the application's
 * project file. woshsrv.pro (WOSH Server) includes this directive:
 * \verbatim
CONFIG += DB_SQL
\endverbatim
 *
 * wosh::application::DataBaseAllocatorStatic is an helper class
 * which maps type-name to its implementation and allocates it.
 *
 *
 * Refer to wosh::DataBase and wosh::DataBaseManager.
 *
 *
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_FrameWork_DataBase_H__
 #define __WOSH_FrameWork_DataBase_H__

 #include <woshDefs.h>

namespace wosh {
 namespace database { };
 };

 #include <framework/database/SerializableXML.h>
 #include <framework/database/EncoderXML.h>
 #include <framework/database/EncoderXMLCommon.h>

 #include <framework/database/SerializableSQL.h>
 #include <framework/database/EncoderSQL.h>
 #include <framework/database/EncoderSQLCommon.h>


#endif //__WOSH_FrameWork_DataBase_H__
